1. Field of the Invention
The invention is directed to a method for synchronizing program sections of a computer program whose program sections can run in parallel on different processors of a computer.
2. Description of the Related Art
The programming and synchronization of threads is explained in “Win 32 Multithreaded Programming”, Aaron Cohen and Mike Woodring, O'Reilly & Associates Inc., ISBN 1-56592-296-4, particularly on pages 258 through 269 and 301 through 303. Such threads are also referred to as “program sections” below.
Program sections that generate data for another program section are referred to as “producers” or “writers”, and program sections that process such data are referred to as “users” or “readers”. It is necessary that the individual program sections work asynchronously in order to optimally utilize the computing power of a computer having a plurality of processors in the division of the work between the individual program sections. This means that the producer program section can generate as many data as it wishes, and the reader program section can read as many data as are available without having to take the other program section into consideration. The data of a producer program section are packed in packets (messages) by this program section and are entered into a queue from which the reader program section can take and further-process the packets.
The individual program sections are provided with functions that wait until they can put a corresponding packet in a queue or until a corresponding packet has arrived to be read which assures the correct allocation of the data to the functions that process them and assures that the transport of the data is synchronized.
The synchronization of the data transfer between individual program sections can be implemented internally or externally. “Internal synchronization” means a synchronization in which the individual synchronization events are implemented by the program sections. In contrast, “external synchronization” is implemented using programs formed outside of the program sections. An external synchronization is preferably employed for data structures that are simultaneously used by different program sections. For the data transfer between individual program sections, it is standard to internally synchronize them. It is assumed that an internal synchronization is easier to realize here and the corresponding programs are shorter.
One goal of such synchronization mechanisms is that they can be utilized in an optimally versatile way, i.e., that they can be employed by the greatest variety of program sections. The queues mentioned above are an example of communication mechanisms that can be employed in a very versatile way. However, they generate a considerable administration outlay, since the data must be packed in corresponding packets, these packets must be provided with corresponding information, must be correspondingly sent by the producer program sections, must be accepted by the queue and must be in turn taken by the reader program section, read out and compiled. This general employability of the queues is obtained at the expense of a high administration outlay.
Program sections run fastest on different processors when they are programmed with an asynchronous data transfer. Given such an asynchronous data transfer, for example, a program section can output a query for data and subsequently undertake a different processing of data while it waits to receive the requested data. Such an asynchronous data transfer is highly efficient but very hard to program.
One problem of these computer programs distributed onto a plurality of program sections is that a test in which the program sections run simultaneously on a plurality of processors is difficult to implement since different errors can occur depending on how the processing of the individual program sections overlap in terms of time. This can result in, e.g., a one-in-a-thousand chance of an unpredictable error occurring, even thought the computer program functions correctly every other time. For a dependable test in practice, it is necessary that such synchronization methods be tested with a multi-CPU computer as a prerequisite. Such computers comprise a plurality of processors that can simultaneously process different program sections.
A method for synchronization program sections must therefore not only utilize an efficient data transfer and be versatile, but must also be fashioned as simply as possible so that no unreasonably great engagement is needed when testing the computer program.
Tanenbaum, Andrew, Moderne Betriebssystems, Carl Hanser Verlag Munich Vienna, 1994, ISBN 3-446-17472-9, pages 40 through 54, discloses various methods for solving multi-tasking jobs in operating systems. Chapter 2.5 describes “semaphores” with which the shared employment of buffer memory sections by write program sections and read program sections can be controlled. The control thereby ensues in program sections that respectively have a prescribed buffer section size.
The employment of ring buffers is explained in Zilker, Praxis des Multitasking, Franzis-Verlag GmbH, Munich, 1987, ISBN 3-7723-8561-3, pages 45 through 61. Such ring buffers are also characterized by a permanently prescribed size of the pre-sections. This publication also describes the employment of queues (messages), in which the respective buffer sections also have a fixed length.
German patent document DE-C1-198 57 332 discloses a method for synchronizing processes in which an indicator is allocated to a semaphore, a participating program section being capable of indicating a change of the semaphore with this indicator.